Add x402 BCH payment support for HTTP requests#1
Conversation
- Add pay command: paytaca pay <url> for HTTP requests with x402 payment - Add X402Payer class integrating with LibauthHDWallet for signing - Add x402 types (PaymentRequired, PaymentPayload, Authorization, etc.) - Add utility functions for header parsing and payload building - Support BCH mainnet and chipnet via bip122 CAIP-2 network format - Uses bitcoinjs-message for BCH message signing (same as bch-js) - Payment flow: request -> 402 -> parse headers -> broadcast BCH tx -> retry with signature
- Add --dry-run flag to pay command for previewing payment without executing - Add --json flag for machine-readable output (useful for AI agents) - Add new 'check' command to pre-verify x402/BCH support before paying - Refactor pay command into separate handlers for human/dry-run/JSON output - JSON output includes success status, payment txid, response data, and errors
- Add 'paytaca opencode' command for managing opencode skill - Supports: install, uninstall, status actions - Installs skill to ~/.config/opencode/skills/paytaca/ - Skill teaches opencode to use paytaca check/pay for 402 handling - Include skills/ directory in npm package distribution
- Fix address extraction in pay.ts to properly parse CashAddress format from payment URLs like 'bch:bitcoincash:qp...' extracting 'bitcoincash:qp...' - Fix payload field in Authorization to contain stringified JSON instead of signature, allowing server to access payment recipients - Fix x402-server to parse payload as JSON string instead of base64
- Fix payment URL parsing to not double-prefix with 'bch:' when address already has bitcoincash: prefix - Add --payer option to allow custom payer identifier (e.g., user ID for server-side lookups) instead of always using wallet address - Add recipient address output after successful payment - Add payment request payload logging on x402 server for debugging
- Replace HTTP header-based 402 responses with JSON body format - Use PAYMENT-SIGNATURE header with JSON-serialized PaymentPayload - Implement BCH network validation (bip122 CAIP-2 format) - Use libauth secp256k1 for message signing instead of bitcoinjs-message - Add network parameter to selectBchPaymentRequirements for validation - Update server to return v2.2 compliant PaymentRequired JSON - Update pay and check commands for new x402 format
Code Review Summary✅ Positive Aspects
|
- Add payment confirmation prompt in pay command before executing BCH transactions - Remove unused imports (signMessageBCH from pay.ts, parsePaymentResponse from wallet/x402.ts) - Extract shared skill utilities to src/utils/skill.ts - Move Claude command to its own file for extensibility - Add SUPPORTED_ASSISTANTS array for easy AI assistant integration
|
Based on my review of the code, here's my assessment: ✅ Positive Aspects
|
- Add Vitest and @vitest/ui as dev dependencies - Add test and test:watch scripts to package.json - Add vitest.config.ts configuration - Add x402.test.ts with 20 tests covering: - PaymentRequired JSON parsing - BCH payment requirement selection - PaymentPayload and Authorization building - PaymentResponse parsing - Network helper functions
|
Based on my comprehensive review of the PR, here's my assessment: ✅ ApproveSecurity Confirmation: User confirmation IS properly implemented at Architecture: Clean separation of concerns:
Testing: Tests ARE included in Documentation: Excellent quality:
AI Integration: Well-designed features:
Minor cleanup needed:
Overall: This is a well-implemented, secure, and thoroughly documented PR. The x402 BCH payment functionality is complete and production-ready. |



Summary
paytaca paycommand for making HTTP requests to x402-enabled APIspaytaca checkcommand to preview payment requirements before spendingpaytaca opencodeandpaytaca claudecommands to install x402 skill for AI agentsCommands Added
paytaca check <url>paytaca pay <url>paytaca opencodepaytaca claudeKey Features
--jsonflag for machine-readable responses--dry-runto preview payments without executingFiles Changed
src/commands/pay.ts- Main payment handlersrc/commands/check.ts- Payment check/previewsrc/commands/opencode.ts,src/commands/claude.ts- Skill installationsrc/wallet/x402.ts- Payment signing and verificationsrc/utils/x402.ts- Header parsing, payment requirement selectionsrc/types/x402.ts- Type definitionsx402-server/- Reference server implementationskills/paytaca/SKILL.md- AI agent skill instructions